package fun.qu_an.minecraft.mini_games_helper.client.mixin.recipebook;

import fun.qu_an.minecraft.mini_games_helper.client.handle.ForceOptionHelperVanilla;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.recipebook.RecipeBookWidget;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(RecipeBookWidget.class)
public abstract class MixinRecipeBookWidget {
	@Shadow protected MinecraftClient client;

	@Inject(method = "isOpen", at = @At("HEAD"), cancellable = true)
    public void isOpen(CallbackInfoReturnable<Boolean> info) {
		if (client.interactionManager != null
			&& ForceOptionHelperVanilla.isDisableRecipeBook(client.interactionManager.getCurrentGameMode())) {
			info.setReturnValue(false);
		}
	}
}
